/*
 * @lc app=leetcode.cn id=922 lang=typescript
 *
 * [922] 按奇偶排序数组 II
 */

// @lc code=start
// 数组映射
function sortArrayByParityII(nums: number[]): number[] {
    let result: number[] = [];
    let odd = 0;
    let even = 0;
    for (let i = 0; i < nums.length; i++) {
        const element = nums[i];
        if (element % 2) {
            result[2 * odd + 1] = element;
            odd++;
        } else {
            result[2 * even] = element;
            even++;
        }
    }
    return result;
}
// @lc code=end
